package com.dawnClass.service.impl;


import com.dawnClass.mapper.ConsumerMapper;
import com.dawnClass.pojo.*;
import com.dawnClass.service.InformationService;
import com.dawnClass.util.ServiceResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class InformationServiceImpl implements InformationService {
    @Autowired
    private ConsumerMapper consumerMapper;



    @Override
    public ServiceResponse update(Consumer consumer,String consumerName, String consumerGender, String consumerEmail,
                                  String consumerHobby, String Other1,String consumerProfile) {



        consumer.setConsumerName(consumerName);
        consumer.setConsumerGender(consumerGender);
        consumer.setConsumerEmail(consumerEmail);
        consumer.setConsumerHobby(consumerHobby);
        consumer.setOther1(Other1);
        consumer.setConsumerProfile(consumerProfile);
        int rows =  consumerMapper.updateByPrimaryKey(consumer);
        if(rows >0)
            return ServiceResponse.updataSuccess(consumer);
        return ServiceResponse.updataFail(null);
    }

    @Override
    public ServiceResponse getById(Integer consumerId) {

        Consumer consumer = consumerMapper.selectByPrimaryKey(consumerId);

        int rows = consumerMapper.updateByPrimaryKey(consumer);
        if(rows>0){
            return ServiceResponse.updataSuccess(rows);
        }else
            return ServiceResponse.updataFail(null);
    }

    @Override
    public ServiceResponse getByConsumerId(Integer consumerId) {

        ConsumerExample consumerExample = new ConsumerExample();
        consumerExample.createCriteria().andConsumerIdEqualTo(consumerId);
        List<Consumer> consumerList = consumerMapper.selectByExample(consumerExample);
        return ServiceResponse.getSuccess(consumerList);
    }
}
